package vip.bblog.cunadmin.modules.file.config;

import javax.servlet.MultipartConfigElement;

import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer{
	public void addResourceHandlers(ResourceHandlerRegistry registry){
//		registry.addResourceHandler("/upload/**").addResourceLocations("file:C:/upload/");
        registry.addResourceHandler("/upload/**").addResourceLocations("file:/images/upload/");
	}

	/**
    * 文件上传配置
    * @return
    */
   @Bean
   public MultipartConfigElement multipartConfigElement() {
      MultipartConfigFactory factory = new MultipartConfigFactory();
    //文件最大200M,DataUnit提供5中类型B,KB,MB,GB,TB
      factory.setMaxFileSize(DataSize.of(2000, DataUnit.MEGABYTES));
      /// 设置总上传数据总大小200M
      factory.setMaxRequestSize(DataSize.of(2000, DataUnit.MEGABYTES));
      return factory.createMultipartConfig();
   }
}
